package com.cp;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.besjon.pojo.CpLeto;
import com.besjon.pojo.Dlt;
import com.step.web.Netutil;

public class LetoUtil {
	private static final String[] mys = { "02#07#11#16#18", "01#05", "01#06", "05#06" };
	//  public static void main(String[] args) { System.err.println(getNew(null)); }
	public static String getNew(String path) {
		String last = Netutil.fromFile(null);
		JSONArray jarr = JSON.parseArray(last);
		StringBuilder sd = new StringBuilder();
		if (null != jarr) {
			JSONObject jobj = (JSONObject) jarr.get(0);
			if (jobj != null) {
				Dlt dlt = jobj.getObject("dlt", Dlt.class);
				CpLeto eo1 = getLeto(mys[0], mys[1], dlt.getNumberCode());
				CpLeto eo2 = getLeto(mys[0], mys[2], dlt.getNumberCode());
				CpLeto eo3 = getLeto(mys[0], mys[3], dlt.getNumberCode());
				sd.append(dlt.getTerm()).append("=>")
				.append(JSON.toJSONString(dlt.getNumberCode())).append("\n")
				.append(JSON.toJSONString(eo1)).append("\n")
				.append(JSON.toJSONString(eo2)).append("\n")
				.append(JSON.toJSONString(eo3));
			}
		}
		return sd.toString();
	}

	private static CpLeto getLeto(String red, String blue, List<String> kjs) {
		CpLeto eo1 = getLeto(red, kjs, 0, 5);
		CpLeto eo2 = getLeto(blue, kjs, 5, 7);
		eo1.setZb(eo2.getZb());
		eo1.setZbs(eo2.getZbs());
		eo1.setBuyNos(red + "#" + blue);
		eo1.setResult(zj(eo1.getZr() + "" + eo1.getZb()));
		return eo1;
	}

	private static CpLeto getLeto(String org, List<String> kjs, int start, int end) {
		CpLeto eo = new CpLeto();
		Long rel = 0L;
		String[] orgs = org.split("#");
		StringBuilder sd = new StringBuilder();
		for (String y : orgs) {
			for (int i = start; i < end; i++) {
				if (y.equals(kjs.get(i))) {
					rel++;
					sd.append(y).append("#");
					break;
				}
			}
		}
		eo.setZbs(sd.toString());
		eo.setZrs(eo.getZbs());
		eo.setZr(rel);
		eo.setZb(rel);
		return eo;
	}

	// 中将规则
	private static String[] zjs = { "152", "251", "350", "442", "541", "632", "740", "831", "822", "930", "921", "912",
			"902" };

	private static String zj(String rb) {
		StringBuilder sd = new StringBuilder();
		Integer money = 0;
		for (String zj : zjs) {
			if (zj.lastIndexOf(rb) > 0) {
				sd.append(zj).append(",");
				money = addMoney(money,zj);
			}
		}
		if (sd.length() == 0) {
			return "未中奖!";
		}
		return sd.append(money).toString();
	}
	
	private static Integer addMoney(Integer m,String no) {
		Integer n = Integer.valueOf(no.substring(0, 1));
		switch (n) {
		case 3:
			m =+ 10000;
			break;
		case 4:
			m =+ 3000;
			break;
		case 5:
			m =+ 300;
			break;
		case 6:
			m =+ 200;
			break;
		case 7:
			m =+ 100;
			break;
		case 8:
			m =+ 15;
			break;
		case 9:
			m =+ 5;
			break;
		default:
			break;
		}
		
		return m;
	}

}
